package gmmxEditor.GUI;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;

import javax.swing.BorderFactory;
import javax.swing.JColorChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

/* ColorChooserDemo.java requires no other files. */
public class ColorPicker extends JPanel implements ChangeListener {

	private static final long	serialVersionUID	= 7031553352901120056L;
	protected JColorChooser		tcc;
	protected JLabel			banner;

	public Color				selectedColor;

	public ColorPicker(Color preselected) {
		super(new BorderLayout());

		//Set up the banner at the top of the window
		this.banner = new JLabel("COLOR PREVIEW", SwingConstants.CENTER);
		this.banner.setForeground(Color.yellow);
		this.banner.setBackground(Color.blue);
		this.banner.setOpaque(true);
		this.banner.setFont(new Font("SansSerif", Font.BOLD, 24));
		this.banner.setPreferredSize(new Dimension(100, 65));

		JPanel bannerPanel = new JPanel(new BorderLayout());
		bannerPanel.add(this.banner, BorderLayout.CENTER);
		bannerPanel.setBorder(BorderFactory.createTitledBorder("Banner"));

		//Set up color chooser for setting text color
		this.tcc = new JColorChooser(this.banner.getForeground());
		this.tcc.getSelectionModel().addChangeListener(this);
		this.tcc.setBorder(BorderFactory.createTitledBorder("Choose Text Color"));

		this.tcc.setColor(preselected);

		this.add(bannerPanel, BorderLayout.CENTER);
		this.add(this.tcc, BorderLayout.PAGE_END);
	}

	@Override
	public void stateChanged(ChangeEvent e) {
		Color newColor = this.tcc.getColor();
		this.banner.setForeground(newColor);
		this.selectedColor = newColor;
	}
}